package game;


public abstract class Abstract2DMap extends AbstractRunnable
{
    private Point size;
    
    public Point getSize()
    {
        return size;
    }
    
    public void setSize(Point size)
    {
        this.size = size;
    }
    
    protected int calculateIndex(int x, int y)
    {
        if (x < 0 || x > size.getWidth())
        {
            throw new IndexOutOfBoundsException(x + " not in 0-" + size.getWidth());
        }
        if (y < 0 || y > size.getHeight())
        {
            throw new IndexOutOfBoundsException(y + " not in 0-" + size.getHeight());
        }
        int index = (size.getWidth() * y) + x;
        return index;
    }
    
    protected Point calculatePosition(int index)
    {
        int x = 0;
        int y = 0;
        // find y
        y = index / size.getX();
        x = index - (y * size.getX());
        return new Point(x, y);
    }
}
